/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pruebaVisitor;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Instructor
 */
class ShoppingCart {

    private List<Product> products = new ArrayList<Product>();

    /**
     * @return the products
     */
    public List<Product> getProducts() {
        return products;
    }

    double getTotalPrice() {
        double totalPrice = 0;
        DiscountVisitor discountVisitor = new DiscountVisitor();
        IVAVisitor ivaVisitor = new IVAVisitor();
        for (Product product : products) {
            totalPrice += product.getPrice();
            product.accept(discountVisitor);
            product.accept(ivaVisitor);
        }
        System.out.println("Total price: " + totalPrice);
        System.out.println("Discount: (" + discountVisitor.getTotalDiscount() + ")");
        System.out.println("IVA: " + ivaVisitor.getIva());
        return totalPrice - discountVisitor.getTotalDiscount() + ivaVisitor.getIva();
    }

    void add(Product prod) {
        this.products.add(prod);
    }

}
